package com.rain.shoppingscienceproj.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.rain.shoppingscienceproj.R;
import com.rain.shoppingscienceproj.module.Massage;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: Rain
 * Create: 2018/1/18 9:29
 */

public class MessageStoreAdapter extends RecyclerView.Adapter<MessageStoreAdapter.MyViewHolder> {

    private Context mContext;
    private List<Massage> list;

    public void setList(List<Massage> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    public MessageStoreAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_message_item, parent, false);//解决宽度
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {

        Massage storesActivityTab = list.get(position);
        holder.tv_title_name.setText(storesActivityTab.getTitle());
        holder.tv_title_time.setText(storesActivityTab.getCtime());
        holder.tv_title_data.setText(storesActivityTab.getMassage());


    }

    @Override
    public int getItemCount() {
        if (list == null)
            return 0;
        else
            return list.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_title_name)
        TextView tv_title_name;
        @BindView(R.id.tv_title_time)
        TextView tv_title_time;
        @BindView(R.id.tv_title_data)
        TextView tv_title_data;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
